#ifndef H1010_H_
#define H1010_H_

#include "DataType.h"
#include <stdint.h>

#define TS 0
enum objectType {OBJ_T_SO, OBJ_T_SZ, OBJ_T_RL, OBJ_T_SI, OBJ_T_NULL};
enum objectNumber {OBJ_1, OBJ_2, OBJ_3, OBJ_4, OBJ_5, OBJ_6, OBJ_7, OBJ_8, OBJ_9, OBJ_10, OBJ_11, OBJ_12,
	OBJ_13, OBJ_14, OBJ_15, OBJ_17, OBJ_18, OBJ_19, OBJ_20, OBJ_COUNT, OBJ_NULL=OBJ_COUNT
};
enum objectStatus {OBJ_S_NULL, OBJ_S_INACTIVE, OBJ_S_ACTIVE, OBJ_S_INVALID};

enum panel_types {
	PT_NONE = -1,
	PT_FIRE_DETECTION_AND_CONTROL,
	PT_EXTINGUISHANT_RELEASE,
	PT_FINE_WATER_SPRAY,
	PT_PROPAK
};
#define DEFAULT_PANEL_TYPE panel_types.PT_PROPAK

//int def1 = panel_types.PT_PROPAK;
//int def2 = PT_PROPAK;


#define FLT_LEVEL_FACTOR 0.025
#define	ZERO_LEVEL_FACTOR   0.025,
#define	MAX_LEVEL_FACTOR  0.1

enum SI_IG_DSP {
	IG_DSP_POURCENT = 0x00,
	IG_DSP_LEL = 0x01,
	IG_DSP_PPM = 0x02
};

enum GA_pre_alert {
	PRE_ALERT_MIN = 0,
	PRE_ALERT_MAX = 255,
	PRE_ALERT_FACTOR = 1
};
enum GA_alert {
	ALERT_MIN = 0,
	ALERT_MAX = 255,
	ALERT_FACTOR = 1
};
enum GA_alert_on {
	ALERT_ON_MIN = 0,
	ALERT_ON_MAX = 255,
	ALERT_ON_FACTOR = 1//0.5
};
enum GA_alert_off {
	ALERT_OFF_MIN = 0,
	ALERT_OFF_MAX = 255,
	ALERT_OFF_FACTOR = 1//0.5
};
enum GA_evac_min {
	EVAC_MIN_MIN = 0,
	EVAC_MIN_MAX = 255,
	EVAC_MIN_FACTOR = 1
};
enum GA_auto_silence {
	AUTO_SILENCE_MIN = 0,
	AUTO_SILENCE_MAX = 255,
	AUTO_SILENCE_FACTOR = 10
};

enum FWS_pre_release {
	PRE_RELEASE_MIN = 0,
	PRE_RELEASE_MAX = 255,
	PRE_RELEASE_FACTOR = 1
};
enum FWS_abort {
	ABORT_MIN = 0,
	ABORT_MAX = 60,
	ABORT_FACTOR = 1
};
enum FWS_C1 {
	C1_MIN = 0,
	C1_MAX = 255,
	C1_FACTOR = 1
};

#define REV_PROPAK_BIN_LINES       5029

// Maximun lines

#define MAX_BIN_LINES              5029    // Maximum # of binary lines (bytes)
                                           // in any configuration

//-----------------------------------------
// Number of SI, SO, SZ & Output Relays
//-----------------------------------------
#define MAX_SI       12
#define MAX_SI_EXT   0
#define TOTAL_SI     (MAX_SI + MAX_SI_EXT)
#define TOTAL_SI_WAR 8

#define MAX_SO       4
#define MAX_SO_EXT   0
#define TOTAL_SO     (MAX_SO + MAX_SO_EXT)

#define MAX_SZ       12
#define TOTAL_SZ     (MAX_SZ)

#define MAX_REL      4
#define MAX_REL_EXT  16
#define TOTAL_REL    (MAX_REL + MAX_REL_EXT)

#define TOTAL_FWS_SECTORS  8

#define MAX_MESSAGE_CHAR 26
#define SI_MESSAGE_OFFSET 0
#define SO_MESSAGE_OFFSET (SI_MESSAGE_OFFSET + TOTAL_SI )
#define RL_MESSAGE_OFFSET (SO_MESSAGE_OFFSET + TOTAL_SO )
#define SZ_MESSAGE_OFFSET (RL_MESSAGE_OFFSET + TOTAL_REL)

//---------------------------------------------------------------------------
//  GLOBAL DECLARATIONS
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//  The following section contains the 1010 Configuration structures
//  (e.g. HWTest, SI, SO ...). Each of these structures has a corresponding
//  "Revision" control structure (e.g. REV_HWTest, REV_SI, REV_SO ...)
//  which holds software revision flags to indicate which software revision(s)
//  support the corresponding field.
//
//  Example:
//
//  The FWS structure holds among its fields the following two:
//      - DumpOnTimer
//      - StartDumpOnTimer
//  The corresponding REV_FWS structure indicates that:
//      - DumpOnTimer is supported by all Revisions following "REV E"
//      - StartDumpOnTimer is supported by all Revisions following "REV D"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
//  Configuration Structures
//---------------------------------------------------------------------------
struct SysConfigAddress
   {
    BYTE Start;
    BYTE Address;
    BYTE End;
   } ;

struct SysConfig
   {
    BYTE Start;
    unsigned char Slot1 :3;
    unsigned char Slot2 :3;
    unsigned char NumRemoteAnnunciators : 2;
    BYTE End;
   } ;
enum HWTestInhibit {
	HWTestEnabled = 0,
	HWTestDisabled = 1
};
struct HWTests
   {
    BYTE Start;
    unsigned char InhibitACTest : 1;  // bit 0
    unsigned char InhibitUPSTest : 1;  // bit 1 -- not sure what this test is, it is not a selectable item
    unsigned char InhibitGroundFaultTest : 1; // bit 2
    unsigned char InhibitBatteryTest : 1; // bit 3
    unsigned char Unused :4;
    BYTE End;
   } ;

/* ------------------------------------------------------------------*/
/* 			Supervised Inputs										*/
/* ------------------------------------------------------------------*/
enum SI_functions {  // fxn
	SI_Fxn_INHIBIT_INPUT = 0x1,
	SI_Fxn_STATUS_CHANGE = 0x8,
	SI_Fxn_SILENT_STATUS_CHANGE = 0xC,
	SI_Fxn_SUPERVISORY = 0x10,
	SI_Fxn_ALARM_NO_GA = 0x00,
	SI_Fxn_ALARM_NORMAL_GA = 0x40,
	SI_Fxn_ALARM_SKIP_TO_EVAC = 0x80
};
enum SI_latch {
	SI_latch_notLatched = 0,
	SI_latch_isLatched = 1
};
enum SI_fwsEnable {
	SI_fwsEnable_notSet = 0,
	SI_fwsEnable_isSet = 1
};
enum SI_factors {
	RANGE_LEVEL_FACTOR = 1,
	ALARM_LEVEL1_FACTOR = 1,
	ALARM_LEVEL2_FACTOR = 1,
	ALARM_LEVEL3_FACTOR = 1
};
enum SI_type{	// SHORTING		NC/NO	EOL     // config 2
	SI_TYPE1 = 0, 	// YES			NC		NO
	SI_TYPE2,		// YES			NC		YES
	SI_TYPE3,		// YES			NO		NO
	SI_TYPE4,		// YES			NO		YES
	SI_TYPE5,		// NO			N/A		NO
	SI_TYPE6,		// NO			N/A		YES
	SI_TYPE7,		// PARALLEL: SHORTING NO, NON-SHORTING, NO EOL
	SI_TYPE8,		// PARALLEL: SHORTING NO, NON-SHORTING, EOL
	SI_TYPE9,		// SERIES: SHORTING NC, SHORTING NC, EOL
	SI_TYPE10,		// 4-20 mA DEVICE
	SI_TYPE_mask = 0x1F
};
enum SI_config2_mask {
	SI_config2_mask_SI_type = 0x1F,
	SI_config2_mask_notStyleD = 0x20,
	SI_config2_mask_SwLatch = 0x40,
	SI_config2_mask_FWSEnable = 0x80
};

struct SI
   {
//    AnsiString GenericName;  // SI0:, SO1:, FWS2: etc..
//    AnsiString Alias;        // Assigned name
//    AnsiString Name;         // Full name = GenericName + Alias
//    AnsiString Type;
//    AnsiString Message;

    BYTE Start;
    BYTE AlarmEntryTimer;
    BYTE AlarmExitTimer;
    BYTE SmokeCheckTimer;
    BYTE ResetOnTimer;
    BYTE ResetOffTimer;
    BYTE ConfirmationTimer;
    BYTE ClearTimer;
    BYTE fxn; // SI Function

    unsigned char InputType : 5;  // config 2, bits 0 to 4, 0x1F
    unsigned char NotStyleD : 1; // bit 5, 0x20, always high
    unsigned char SWLatch : 1; // bit 6, 0x40, active high
    unsigned char FWSEntryTimerEnable : 1; // bit 7, 0x80, active high
    BYTE End;

/*    BYTE Start2;
    BYTE Gas_display;
    BYTE Multiplicator;
    BYTE RangeLevelValue;
    BYTE AlarmLevel1Value;
    BYTE AlarmLevel2Value;
    BYTE AlarmLevel3Value;
    BYTE BeamBlockValue;
    BYTE CalibrationValue;
    BYTE FltLevelValue;
    BYTE ZeroLevelValue;
    BYTE MaxLevelValue;
    BYTE dummy;
    BYTE End2;*/

   } ;
struct SI_gas {
    BYTE Start;
    BYTE Gas_display;
    BYTE Multiplicator;
    BYTE RangeLevelValue;
    BYTE AlarmLevel1Value;
    BYTE AlarmLevel2Value;
    BYTE AlarmLevel3Value;
    BYTE BeamBlockValue;
    BYTE CalibrationValue;
    BYTE FltLevelValue;
    BYTE ZeroLevelValue;
    BYTE MaxLevelValue;
    BYTE dummy;
    BYTE End;
};
/* ------------------------------------------------------------------*/
/* 			Supervised Outputs										*/
/* ------------------------------------------------------------------*/
enum SO_configByte_NormallyOnOff {
	SO_configByte_NormallyOn_isOff = 0,
	SO_configByte_NormallyOn_isOn =1,
	SO_configByte_NormallyOn_mask = 0x01
};
enum SO_configByte_InhibitService {
	SO_configByte_InhibitService_isDrive = 1,
	SO_configByte_InhibitService_isOff = 0,
	SO_configByte_InhibitService_mask = 0x02
};
enum SO_configByte_OutputControl {
	SO_configByte_OutputControl_disabled = 0x00,
	SO_configByte_OutputControl_andOr = 0x1, //0x01,
	SO_configByte_OutputControl_genAlarm = 0x2, //0x10,
	SO_configByte_OutputControl_andOrAbort = 0x3, //0x11,
	SO_configByte_OutputControl_mask = 0x18
};
enum SO_configByte_AbortInput {
	SO_configByte_AbortInput_SI1 = 0x000,
	SO_configByte_AbortInput_SI2,
	SO_configByte_AbortInput_SI3,
	SO_configByte_AbortInput_SI4,
	SO_configByte_AbortInput_SI5,
	SO_configByte_AbortInput_SI6,
	SO_configByte_AbortInput_SI7,
	SO_configByte_AbortInput_mask = 0xE0
};
enum SO_configByte_mask {
	SO_configByte_mask_NormallyOn = 0x01,
	SO_configByte_mask_InhibitService = 0x02,
	SO_configByte_mask_Unused = 0x04,
	SO_configByte_mask_OutputControl = 0x18,
	SO_configByte_mask_AbortInput = 0xE0
};
enum SO_Op {
	SO_Op_And = 0,
	SO_Op_Or = 1
};
enum SO_triggerEnum {
	SO_triggers_SI_1 = 0x01,
	SO_triggers_SI_2 = 0x02,
	SO_triggers_SI_3 = 0x04,
	SO_triggers_SI_4 = 0x08,
	SO_triggers_SI_5 = 0x10,
	SO_triggers_SI_6 = 0x20,
	SO_triggers_SI_7 = 0x40,
	SO_triggers_SI_8 = 0x80
};

struct SO_timers {
	BYTE TurnOnDelay;
	BYTE TurnOffDelay;
	BYTE PulsePeriod;
	BYTE PulseOnTimer;
	BYTE PulseOffTimer;
};
struct SO_triggers {
	BYTE SIWarTriggers;
	BYTE SZTriggers;
	BYTE SIHiTriggers;
	BYTE SILoTriggers;
};
struct SO
    {
//     AnsiString GenericName;  // SI0:, SO1:, FWS2: etc..
//     AnsiString Alias;        // Assigned name
//     AnsiString Name;         // Full name = GenericName + Alias
//     AnsiString Type;
     BYTE Start;

     // config byte
     unsigned char NormallyOn : 1; // bit 0, 1=on, 0=off
     unsigned char InhibitService : 1; // bit 1, 1=drive in svc mode, 0=off in svc mode
     unsigned char Unused1 : 1; // bit 2 - n/a
     unsigned char OutputControl : 2; // 00:disabled, 01:andOr, 10:ga, 11:andOrAbort
     unsigned char AbortInput : 3;//000:si1, 001:si2, ..., 111:si8

     // trigger config byte
     unsigned char Term1Op : 1;
     unsigned char Term2Op : 1;
     unsigned char Term3Op : 1;
     unsigned char Term4Op : 1;
     unsigned char Term34Op : 1;
     unsigned char Term23Op : 1;
     unsigned char Term12Op : 1;
     unsigned char Unused2 :1;

     struct SO_triggers term[4];
//     struct SO_triggers term2;
//     struct SO_triggers term3;
//     struct SO_triggers term4;
     /*
     BYTE Term1SIWarTriggers;
     BYTE Term1SZTriggers;
     BYTE Term1SIHiTriggers;
     BYTE Term1SILoTriggers;

     BYTE Term2SIWarTriggers;
     BYTE Term2SZTriggers;
     BYTE Term2SIHiTriggers;
     BYTE Term2SILoTriggers;

     BYTE Term3SIWarTriggers;
     BYTE Term3SZTriggers;
     BYTE Term3SIHiTriggers;
     BYTE Term3SILoTriggers;

     BYTE Term4SIWarTriggers;
     BYTE Term4SZTriggers;
     BYTE Term4SIHiTriggers;
     BYTE Term4SILoTriggers;
*/
     struct SO_timers timers;
/*     BYTE TurnOnDelay;
     BYTE TurnOffDelay;
     BYTE PulsePeriod;
     BYTE PulseOnTimer;
     BYTE PulseOffTimer;
*/
     BYTE End;
    } ;

struct GA
    {
     BYTE Start;
     unsigned char GAEnableSilence : 1;
     unsigned char Unused : 7 ;
     BYTE PreAlertTimer;
     BYTE AlertTimer;
     BYTE EvacMinTimer;
     BYTE AutoSilenceTimer;
     BYTE GAAlertOnTimer;
     BYTE GAAlertOffTimer;
     BYTE End;
    } ;

struct xAbort
    {
     BYTE Start;
     BYTE AbortTimer;
     BYTE End;
    } ;
struct FWS_cfg {
    unsigned char XZone : 1;
    unsigned char EnableDet1PreReleaseDelay : 1;
    unsigned char EnableDet2PreReleaseDelay : 1;
    unsigned char EnableMCPPreReleaseDelay : 1;
    unsigned char LockoffCancel : 1;
    unsigned char ReleaseAbort : 1;
    unsigned char Det1OneShot : 1;
    unsigned char MCPOneShot : 1;
};
struct FWS_cfgInput {
    BYTE Det1Input;
    BYTE Det2Input;
    BYTE MCPInput;
    BYTE LockoffInput;
    BYTE AbortInput;
};
struct FWS_cfgOutput {
    BYTE HPSolenoidOutput;
    BYTE LPSolenoidOutput;
    BYTE PreReleaseAnnOutput;
    BYTE ReleaseAnnOutput;
    BYTE ShutdownOutput;
    BYTE ResetOutput;
};
struct FWS_cfgTimers {
    BYTE PreReleaseTimer;
    BYTE AbortTimer;
    BYTE StartupTimer;
    BYTE DumpOnTimer;
    BYTE DumpOffTimer;
    BYTE PauseTimer;
    BYTE ResetTimer;
    BYTE C1Counter;
    BYTE C2Counter;
    BYTE Interlock;
};
struct FWS
    {
//     AnsiString GenericName;  // SI0:, SO1:, FWS2: etc..
//     AnsiString Alias;        // Assigned name
//     AnsiString Name;         // Full name = GenericName + Alias
//     AnsiString Type;
     BYTE Start;
     struct FWS_cfg cfg;
//     unsigned char XZone : 1;
//     unsigned char EnableDet1PreReleaseDelay : 1;
//     unsigned char EnableDet2PreReleaseDelay : 1;
//     unsigned char EnableMCPPreReleaseDelay : 1;
//     unsigned char LockoffCancel : 1;
//     unsigned char ReleaseAbort : 1;
//     unsigned char Det1OneShot : 1;
//     unsigned char MCPOneShot : 1;
     struct FWS_cfgInput input;
//     BYTE Det1Input;
//     BYTE Det2Input;
//     BYTE MCPInput;
//     BYTE LockoffInput;
//     BYTE AbortInput;
     struct FWS_cfgOutput output;
//     BYTE HPSolenoidOutput;
//     BYTE LPSolenoidOutput;
//     BYTE PreReleaseAnnOutput;
//     BYTE ReleaseAnnOutput;
//     BYTE ShutdownOutput;
//     BYTE ResetOutput;
     struct FWS_cfgTimers timers;
//     BYTE PreReleaseTimer;
//     BYTE AbortTimer;
//     BYTE StartupTimer;
//     BYTE DumpOnTimer;
//     BYTE DumpOffTimer;
//     BYTE PauseTimer;
//     BYTE ResetTimer;
//     BYTE C1Counter;
//     BYTE C2Counter;
//     BYTE Interlock;
     BYTE End;
    } ;

// Revision Byte
struct REVNO
    {
     BYTE Start;
     BYTE Revision;
     BYTE PadByte;
     BYTE End;
    } ;

// Added in REV_FWS02
struct FWS_Ext02
    {
     BYTE Start;
     BYTE ReleaseModeOutput;
     BYTE FirstDumpOnTimer;
     BYTE End;
    } ;

 // Display message
 struct DSP_Message {
     BYTE Start;
     BYTE Message[MAX_MESSAGE_CHAR];
     BYTE Message2[MAX_MESSAGE_CHAR];
     BYTE Message3[MAX_MESSAGE_CHAR];
     BYTE End;
 };
 struct configMemRAM_t {
 	struct SysConfigAddress sysConfigAddress;
 	struct SysConfig sysConfig;
 	struct SI si[TOTAL_SI];
 	struct SO sz[TOTAL_SZ];
 	struct SO so[TOTAL_SO];//TOTAL_REL];
 	struct SO rl[TOTAL_REL];
 	struct HWTests hwTests;
 	struct GA ga;
 	struct xAbort xabort;
 	struct FWS fws[TOTAL_FWS_SECTORS];
 	struct REVNO revno;
 	struct FWS_Ext02 fwsEx02[TOTAL_FWS_SECTORS];
 	struct SI_gas siGas[TOTAL_SI];
 	struct DSP_Message dspMessage[48];
 };
extern const struct configMemRAM_t * pConfigMemRAM;
 #endif /* H1010_H_ */
